package 小测试;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

/**
 * Created by Administrator on 2017/8/19.
 */
public class TTtest {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入有多少组：");
        int n = scanner.nextInt(); //n组
        String[] arrAi = new String[n]; //存每组人数初始值 + 人数
        int init=1; //初始数
        for (int i = 0; i < n; i++) {
            System.out.println("请输入每组人数：");
            int num=scanner.nextInt(); //录入每组人数
            arrAi[i]= init+"_"+num;
            init+=num; //第i+1组人数开始值
        }

        System.out.println(Arrays.toString(arrAi));
        System.out.println("请输入有多少个询问：");
        int q = scanner.nextInt(); //Q个询问
        int[] arrQi = new int[q]; //存询问的编号
        for (int i = 0; i < q; i++) {
            System.out.println("请输入每组询问的编号：");
            int index=scanner.nextInt(); //录入询问的编号
            arrQi[i]=index;
        }
        System.out.println(Arrays.toString(arrQi));

        out:for (int i = 0; i < arrQi.length; i++) {
            int index=arrQi[i];
            //遍历每组编号,查看是否在范围内
            in:for (int j = 0; j < n; j++) {
                String[] split = arrAi[j].split("_");
                int begin=Integer.parseInt(split[0]); //起始值
                int end=Integer.parseInt(split[1]); //个数
                if(begin<=index && index<(begin+end))
                {
                    System.out.println(j+1); //第几组
                }
            }
        }
    }
}
